import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'
const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    styleImport({
      libs: [{
        libraryName: 'element-plus',
        esModule: true,
        ensureStyleFile: true,
        resolveStyle: (name) => {
          name = name.slice(3)
          return `element-plus/packages/theme-chalk/src/${name}.scss`;
        },
        resolveComponent: (name) => {
          return `element-plus/lib/${name}`;
        },
      }]
    })
  ],
  base: './',
    // 静态资源服务的文件夹，默认public
    publicDir: 'public',
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src')
        },
        extensions: ['.js', '.vue', '.json', '.scss', '*']
    },
    server: {
      // 服务器主机名，如果允许外部访问，可设置为"0.0.0.0"
      host: '0.0.0.0',
      port: 56438, // 服务器端口号
      open: false, // 是否自动打开浏览器
      // 代理
      proxy: {
          '/crossDomain': {
              target: 'http://10.1.49.72:42081',
              changeOrigin: true,
              rewrite: (path) => path.replace(/^\/crossDomain/, '')
          }
      }
  }
})
